package com.singzi.leetcode.N100;

import java.util.ArrayList;
import java.util.List;


class TreeNode {

    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {

        this.val = val;
        this.left = left;
        this.right = right;
      }
  }

public class T0098 {
    private List<Integer> list = new ArrayList<>();
    public static void main(String[] args) {
        TreeNode tree1 = new TreeNode(6);
        TreeNode tree2 = new TreeNode(3);
        TreeNode tree3 = new TreeNode(8);
        TreeNode treeNode3 = new TreeNode(7, tree2,tree3);
        TreeNode treeNode = new TreeNode(5, tree1,treeNode3);
        Solution0098 solution0098 = new Solution0098();
        System.out.println(solution0098.isValidBST(treeNode));
        System.out.println(solution0098.list);



    }

}
class Solution0098{
    ArrayList<Integer> list = new ArrayList<>();

    public boolean isValidBST(TreeNode root) {
        boolean flag = true;
        inOrder(root);
        for (int i = 0;i<list.size()-1;i++) {
            if(list.get(i) >=list.get(i+1)){
                flag = false;
                break;

            }

        }
        return flag;

    }
    public void inOrder(TreeNode root){
        if(root.left!=null) {
            inOrder(root.left);
        }
        list.add(root.val);
        if(root.right!=null) {
            inOrder(root.right);
        }


    }
}
